/**
 * 将对象类型的键转换为大驼峰格式
 * @example
 * type User = { firstName: string, lastName: string }
 * type ApiUser = ToPascalCase<User> // { FirstName: string, LastName: string }
 */
export type ToPascalCase<T> = T extends object
  ? {
      [K in keyof T as Capitalize<string & K>]: T[K] extends object
        ? ToPascalCase<T[K]>
        : T[K]
    }
  : T;

/**
 * 将对象类型的键转换为小驼峰格式
 * @example
 * type ApiUser = { FirstName: string, LastName: string }
 * type User = ToCamelCase<ApiUser> // { firstName: string, lastName: string }
 */
export type ToCamelCase<T> = T extends object
  ? {
      [K in keyof T as Uncapitalize<string & K>]: T[K] extends object
        ? ToCamelCase<T[K]>
        : T[K]
    }
  : T;

/**
 * API 请求参数类型
 * @example
 * interface CreateUserParams { firstName: string }
 * type ApiParams = RequestType<CreateUserParams> // { FirstName: string }
 */
export type RequestType<T> = ToPascalCase<T>;

/**
 * API 响应数据类型
 * @example
 * interface ApiResponse { FirstName: string }
 * type ResponseData = ResponseType<ApiResponse> // { firstName: string }
 */
export type ResponseType<T> = ToCamelCase<T>;
